package com.uuzz.lottery.agent.gateway.flow.answer.mappingimpl.one2n2nimpl.business.impl;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import com.uuzz.lottery.agent.gateway.base.AbstractAppendCall;
import com.uuzz.lottery.agent.gateway.base.IConvertor;
import com.uuzz.lottery.agent.gateway.base.ISupplier;
import com.uuzz.lottery.agent.gateway.flow.answer.mappingimpl.one2n2nimpl.bottom.IConnectIceProtocol;
import com.uuzz.lottery.agent.gateway.flow.answer.mappingimpl.one2n2nimpl.bottom.IConnectIceProtocolIn;
import com.uuzz.lottery.agent.gateway.flow.answer.mappingimpl.one2n2nimpl.bottom.IConnectIceProtocolOut;
import com.uuzz.lottery.agent.gateway.flow.answer.mappingimpl.one2n2nimpl.business.IBusinessIn;
import com.uuzz.lottery.agent.gateway.flow.answer.mappingimpl.one2n2nimpl.business.IBusinessOut;
import com.uuzz.lottery.agent.gateway.flow.answer.mappingimpl.one2n2nimpl.business.IConnectBusiness;

public abstract class ConnectBusinessSupport<IN extends IBusinessIn,OUT extends IBusinessOut,BIN extends IConnectIceProtocolIn,BOUT extends IConnectIceProtocolOut,P extends IConnectIceProtocol<BIN,BOUT>,SI extends ISupplier<IN,BIN>,CO extends IConvertor<BOUT,OUT>>
extends AbstractAppendCall<IN, OUT, BIN, BOUT, P, SI, CO>
implements IConnectBusiness<IN, OUT, BIN, BOUT, P, SI, CO> {
	
	private final Class<OUT> outClass;
	
	@SuppressWarnings("unchecked")
	public ConnectBusinessSupport() {
		Type[] types = ((ParameterizedType) getClass().getGenericSuperclass())
				.getActualTypeArguments();
		outClass = (Class<OUT>) types[1];
	}

	@Override
	public boolean beforeCall(IN in, OUT out) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void afterCall(IN in, OUT out, BIN bin, BOUT bout) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public OUT defaultOut(IN in) {
		try {
			return outClass.newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
